package com.lx.yygh.api;

import com.lx.yygh.cmn.client.DictFeignClient;
import com.lx.yygh.common.helper.AuthContextHolder;
import com.lx.yygh.common.result.Result;
import com.lx.yygh.model.user.UserInfo;
import com.lx.yygh.service.UserInfoService;
import com.lx.yygh.vo.user.LoginVo;
import com.lx.yygh.vo.user.UserAuthVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @author c先生
 * @date 2022年10月20日 下午 12:22:16
 * @describe
 */
@Api(tags = "用户模块")
@RestController
@RequestMapping("/api/user/")
public class UserInfoApiController {
    @Resource
    UserInfoService userInfoService;
    @Resource
    DictFeignClient dictFeignClient;

    @ApiOperation(value = "用户登录方法")
    @PostMapping("login")
    public Result login(@RequestBody LoginVo loginVo, HttpServletRequest request){
        Map<String,Object> map = userInfoService.loginCheck(loginVo,request);
        return Result.ok(map);
    }

    @ApiOperation(value = "根据toekn中的用户id获取用户信息")
    @GetMapping("auth/getUserInfo")
    public Result getUserInfo(HttpServletRequest request){
        Long userId = AuthContextHolder.getUserId(request);
        UserInfo userInfo = userInfoService.getUserInfo(userId);
        if(userInfo!=null&&userInfo.getCertificatesType()!=null){
            HashMap<String, Object> map = new HashMap<>();
            String name = dictFeignClient.getName(userInfo.getCertificatesType());
            map.put("certificatesTypeString",name);
            userInfo.setParam(map);
        }
        return Result.ok(userInfo);
    }

    @ApiOperation(value = "提交实名认证")
    @PostMapping("auth/userAuah")
    public Result saveUserAuah(@RequestBody UserAuthVo userAuthVo,HttpServletRequest request){
        Long userId = AuthContextHolder.getUserId(request);
        Boolean b = userInfoService.saveUserAuah(userAuthVo,userId);
        return Result.ok();
    }
}






























